import hashlib
from hmac import new
from Crypto.Cipher import AES

key = b"1245558767851456"

IV = b"1245558767851456"

def HmacBack(msg,key):
    m = new(key, msg, hashlib.sha256)
    return m.digest()
    
def Bxor(b1, b2): # use xor for bytes
    parts = []
    for b1, b2 in zip(b1, b2):
        parts.append(bytes([b1 ^ b2]))
    return b''.join(parts)


def DecodeAllTextByAESCBC(text):
    ciper = b""
    while(len(text) != 0):
        encodetext = text[:16]
        text = text[16:]
        encodetext = DeCodeByAESCBC(encodetext, key, IV)
        ciper += encodetext
    return ciper

def DeCodeByAESCBC(text, key, IV):
    aes = AES.new(key, AES.MODE_CBC, IV)
    text = aes.decrypt(text)
    return text

def EncodeAllTextByAESCBC(text):
    ciper = b""
    while(len(text) != 0):
        encodetext = text[:16]
        text = text[16:]
        encodetext = EnCodeByAESCBC(encodetext, key, IV)
        ciper += encodetext
    return ciper

def EnCodeByAESCBC(text, key, IV):
    aes = AES.new(key, AES.MODE_CBC, IV)
    text = aes.encrypt(text)
    return text

